from tabulate import tabulate
import pandas as pd
import saveDataToLocal
import summaryWorkload

re_get = input("是否重新获取数据？(y/n)")
sprint = "202506"
if re_get == "y":
    saveDataToLocal.generateSourceData()
workload_df = summaryWorkload.getWorkload()
save_get = input("是否保存到本地？(y/n)")
if save_get == "y":
    workload_df[
        (workload_df["level"].isin(["bronze", "silver", "gold"]))
        & (workload_df["role"].isin(["frontend", "backend", "test", "producter"]))
        & (workload_df["publishSprint"] == int(sprint))
    ].to_csv(f"./output/workload-summary-{sprint}.csv", index=False)
else:
    print(
        tabulate(
            workload_df[
                (workload_df["level"].isin(["bronze", "silver", "gold"]))
                & (
                    workload_df["role"].isin(
                        ["frontend", "backend", "test", "producter"]
                    )
                )
                & (workload_df["publishSprint"] == int(sprint))
            ].sort_values(by="publishSprint", ascending=True),
            headers="keys",
            tablefmt="grid",
        )
    )

# debug print
# print(
#     tabulate(
#         workload_df[
#             (workload_df["level"].isin(["bronze", "silver", "gold"]))
#             & (workload_df["role"].isin(["frontend", "backend", "test"]))
#             & (workload_df["publishSprint"] == int("202504"))
#         ].sort_values(by="publishSprint", ascending=True),
#         headers="keys",
#         tablefmt="grid",
#     )
# )
# summaryWorkload.testfn()
